Write a query to retrieve the total number of employees in each department.
165
03-Jul-2024
Updated on 03-Jul-2024
Ravi Vishwakarma
03-Jul-2024To retrieve the total number of employees in each department from an SQL Server table, you can use the
COUNT()
function along withGROUP BY
. Here's how you can write the query:Output-
In this query:
EmployeeID
,EmployeeNumber
, etc.).The
GROUP BY Department
clause groups the results by theDepartment
column, andCOUNT(EmployeeID)
counts the number of employees (EmployeeID
) in each department. This will give you the total number of employees in each department listed in your table.